package com.sun.config;/**
 * @author sun
 * @date 2022/1/4 - 15:07
 */

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 自定义失败跳转逻辑
 * @author 孙
 * @date 2022/1/4 15:07
 * @version 1.0
 */
public class MyForwardAuthenticationFailureHandler implements AuthenticationFailureHandler {
    private String url;

    public MyForwardAuthenticationFailureHandler(String url) {
        this.url = url;
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        System.out.println(exception.getMessage());
        response.sendRedirect(url);

    }
}
